﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace simpleDns
{
    public partial class domainConfig : Form
    {
        public DOMAIN dm;
        public int index;
        public domainConfig()
        {
            InitializeComponent();
            dm = new DOMAIN();
            this.Text = "新建域名记录";
            dm.dnsMode = true;
        }
        public domainConfig(DOMAIN domain,int i)
        {
            InitializeComponent();
            tbName.Enabled = false;
            dm = domain;
            index = i;
            tbName.Text = dm.name;
            tbInfo.Text = dm.info;
            rbDnsMode1.Checked = dm.dnsMode;
            rbDnsMode2.Checked = !dm.dnsMode;
            rbEnable1.Checked = dm.enable;
            rbEnable2.Checked = !dm.enable;
            this.Text = "编辑域名记录";
        }

        private void rbDnsMode1_CheckedChanged(object sender, EventArgs e)
        {
            if (rbDnsMode1.Checked)
            {
                dm.dnsMode = true;
            }
                
        }

        private void rbDnsMode2_CheckedChanged(object sender, EventArgs e)
        {
            if (rbDnsMode2.Checked)
            {
                dm.dnsMode = false;
            }
                
        }

        private void rbEnable1_CheckedChanged(object sender, EventArgs e)
        {
            if (rbEnable1.Checked)
            {
                dm.enable = true;
            }
                
        }

        private void rbEnable2_CheckedChanged(object sender, EventArgs e)
        {
            if (rbEnable2.Checked)
            {
                dm.enable = false;
            }
                
        }

        private void tbSave_Click(object sender, EventArgs e)
        {
            if(string.IsNullOrEmpty(tbName.Text))
            {
                MessageBox.Show("域名必填");
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void tbCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void tbName_TextChanged(object sender, EventArgs e)
        {
            dm.name = tbName.Text.Trim();
        }

        private void tbInfo_TextChanged(object sender, EventArgs e)
        {
            dm.info = tbInfo.Text.Trim();
        }
    }
}
